//
//  RootTabBarViewController.m
//  futureLive
//
//  Created by zhoubiwen on 15/11/16.
//  Copyright © 2015年 ZHOU_LI_SUN. All rights reserved.
//

#import "RootTabBarViewController.h"
#import "CustomTabBar.h"
#import "UIView+Frame.h"
#import "DealViewController.h"
#import "SelectLocationViewController.h"
#import "SLCityModel.h"
#import "SearchViewController.h"
#import "SLCityViewController.h"

@interface RootTabBarViewController ()
@property (strong, nonatomic) IBOutlet UIBarButtonItem *leftLocationBarButtonItem;

@end

@implementation RootTabBarViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self addCenterButton];
    
}

#pragma mark - action

- (IBAction)leftLocationSearchBarButtonItemAction:(id)sender {
    
    SelectLocationViewController *selectLocationVC = [[SelectLocationViewController alloc]initWithStyle:UITableViewStylePlain];
    selectLocationVC.leftBarButtonItemTitle = self.navigationItem.leftBarButtonItem.title;
    __weak UIBarButtonItem *barButtonItem = self.navigationItem.leftBarButtonItem;
    selectLocationVC.myBlock = ^(SLCityModel *model){
        barButtonItem.title = model.cityName;
    };
    [self.navigationController pushViewController:selectLocationVC animated:YES];
    
//    SLCityViewController *slcityVC = [[SLCityViewController alloc]initWithNibName:@"SLCityViewController" bundle:nil];
//    
//    [self.navigationController pushViewController:slcityVC animated:YES];
    
}

- (IBAction)searchBarAction:(id)sender {
    
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    
    [self.navigationController pushViewController:searchVC animated:YES];
   
}


/**
 *  实现tabbar上面有一个突出的标签
 */
- (void)addCenterButton {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *buttonImage = [UIImage imageNamed:@"17.jpg"];
    [button setImage:buttonImage forState:UIControlStateNormal];
    [button addTarget:self action:@selector(centerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.clipsToBounds = YES;
    button.layer.cornerRadius = buttonImage.size.width / 2;
    button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
    CGFloat CenterInterval = button.frame.size.height - self.tabBar.height;
    if (CenterInterval < 0) {
        button.center = self.tabBar.center;
    }else {
        CGPoint center = self.tabBar.center;
        center.y = center.y - CenterInterval / 2 - 10;
        button.center = center ;
    }
    [self.view addSubview:button];
}

/**
 *  突出标签触发方法
 *
 */
- (void)centerButtonAction:(UIButton *)button {
    
    button.selected = YES;
    
    DealViewController *dealVC = [DealViewController defaultDealViewController];
    
    [self.navigationController pushViewController:dealVC animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
